package org.com.system.util.model;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

import org.apache.commons.beanutils.BeanUtils;
import org.com.system.util.mate.Order;
import org.com.system.util.utils.DateUtils;
import org.com.system.util.utils.ModelUtils;

@MappedSuperclass
public class Model {

	@Order
	private String createTime;//创建时间
	
	private String createPerson;//创建人
    
	@Column(name="create_time",length=45)
	public String getCreateTime() {
		if(null==createTime){
			this.createTime=DateUtils.getSystime();
		}
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	@Column(name="create_person",length=45)
	public String getCreatePerson() {
		return createPerson;
	}

	public void setCreatePerson(String createPerson) {
		this.createPerson = createPerson;
	}
	
	
	@Override
	public boolean equals(Object obj) {
		if(null!=obj&&obj.getClass()==this.getClass()){
			if(obj.hashCode()==this.hashCode()){
				return true;
			}
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		int hashCode=this.getClass().getName().hashCode();
		try{
		    String id=BeanUtils.getSimpleProperty(this, "id");
		    if(null!=id&&!"".equals(id)){
				hashCode+=id.hashCode();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return hashCode;
	}
	
	@Override
	public String toString() {
		StringBuilder sber=new StringBuilder();
		String[] filedNames=ModelUtils.getFieldNames(this.getClass(),true);
		for(String name:filedNames){
			try{
			    sber.append(name+"="+BeanUtils.getProperty(this, name)+";");
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return sber.toString();
	}
	
	
}
